package com.ynet.middleground.riskmanage.mq.producer;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import com.ynet.core.log.IfpLogger;
import com.ynet.middleground.riskmanage.mq.SourcePledge;

/**
 * @author liulx
 * @description 质押监管类推送处理
 * @date 2020-08-21 14:06
 */
@EnableBinding({SourcePledge.class})
@Component
public class PledgeProducer {

    @Autowired
    private SourcePledge sourcePledge;

    /**
     * MQ 推送【换货指令结果】给核心系统
     * 
     * @param data 换货指令结果
     */
    public void sendMessagesExchange(Map<String, Object> data) {
        IfpLogger.info("mq", "MQ 推送【换货指令结果】给核心系统，往 Binding-{} 推送信息-{}", SourcePledge.JKZTFK_TO_BLXD_HHZLJG, data);
        Map<String, Object> headers = new HashMap<>(1);
        // 渠道订阅要统一，tags 用 in
        headers.put("TAGS", "in");
        MessageHeaders messageHeaders = new MessageHeaders(headers);
        Message<Map<String, Object>> message = MessageBuilder.createMessage(data, messageHeaders);
        this.sourcePledge.noticeExchange().send(message);
    }

    /**
     * MQ 推送【静态质押监管结果】给核心系统
     *
     * @param data 静态质押监管结果
     */
    public void sendMessagesStaticResult(Map<String, Object> data) {
        IfpLogger.info("mq", "MQ 推送【静态质押监管结果】给核心系统，往 Binding-{} 推送信息-{}", SourcePledge.JKZTFK_TO_BLXD_ZYJGJTJG, data);
        Map<String, Object> headers = new HashMap<>(1);
        // 渠道订阅要统一，tags 用 in
        headers.put("TAGS", "in");
        MessageHeaders messageHeaders = new MessageHeaders(headers);
        Message<Map<String, Object>> message = MessageBuilder.createMessage(data, messageHeaders);
        this.sourcePledge.noticeStatic().send(message);
    }

    /**
     * MQ 推送【动态质押监管结果】给核心系统
     *
     * @param data 动态质押监管结果
     */
    public void sendMessagesDynamicResult(Map<String, Object> data) {
        IfpLogger.info("mq", "MQ 推送【动态质押监管结果】给核心系统，往 Binding-{} 推送信息-{}", SourcePledge.JKZTFK_TO_BLXD_ZYJGDTJG, data);
        Map<String, Object> headers = new HashMap<>(1);
        // 渠道订阅要统一，tags 用 in
        headers.put("TAGS", "in");
        MessageHeaders messageHeaders = new MessageHeaders(headers);
        Message<Map<String, Object>> message = MessageBuilder.createMessage(data, messageHeaders);
        this.sourcePledge.noticeDynamic().send(message);
    }

}
